package gui.inventory;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import persistence.DataPersistor;

import core.Container;
import core.ContainerFacade;

public class ProductContainerDataTest {
	Container _su;
	Container _pg;

	@Before
	public void setUp() throws Exception {
		DataPersistor.instance().init("-serial");
		ContainerFacade.clearAllData();
		_su = ContainerFacade.instance().addStorageUnit("Bathroom Closet");
		_pg = ContainerFacade.instance().addProductGroup(_su, "Soaps","3","count");
		ContainerFacade.instance().addProductGroup(_pg, "Shampoo","3","count");
		ContainerFacade.instance().addProductGroup(_pg, "Conditioner","3","count");
		ContainerFacade.instance().addProductGroup(_su, "Toothpaste","3","count");
	}

	@Test
	public void test() {
		ProductContainerData data = new ProductContainerData(_su);
		
		assertEquals("Bathroom Closet",data.getName());
		assertEquals("Bathroom Closet should have 2 children",2,data.getChildCount());
		assertEquals("Child 1 should be \"Soaps\"","Soaps",data.getChild(0).getName());
		assertEquals("Child 1 should have 2 children",2,data.getChild(0).getChildCount());
		assertEquals("Grandchild 1 should be shampoo","Shampoo",
				data.getChild(0).getChild(1).getName());
		assertEquals("Shampoo should not have children",0,
				data.getChild(0).getChild(1).getChildCount());
		assertEquals("Grandchild 2 should be conditioner", "Conditioner",
				data.getChild(0).getChild(0).getName());
		assertEquals("Grandchild 2 should not have children", 0,
				data.getChild(0).getChild(0).getChildCount());		
		assertEquals("Child 2 should be Toothpaste","Toothpaste",data.getChild(1).getName());
		assertEquals("Child 2 should have no children",0,data.getChild(1).getChildCount());
		
		assertEquals("Test tagging",_su,data.getContainer());
		assertEquals("Test tagging",_pg,data.getChild(0).getContainer());
	
	}

}
